<template>
  <div class="login-container">
    <el-form
      ref="registerForm"
      :model="registerForm"
      :rules="registerRules"
      label-position="top"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="registerForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="registerForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="register">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { register } from "@/api/login";

export default {
  name: "RegisterView",
  data() {
    return {
      registerForm: {
        username: "",
        password: "",
      },
      registerRules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    register() {
      this.$refs.registerForm.validate(async (valid) => {
        if (valid) {
          const res = await register(this.registerForm);
          if (res.data.success) {
            // 注册成功后跳转到登录页
            this.$router.push("/login");
          }
        }
      });
    },
  },
  created() {
  }
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: url("@/assets/background.png");
  background-size: cover; /* 让背景图片填满整个容器 */
  background-position: center; /* 将背景图片居中 */
}
.code-image{
  width: 100px;
  height: 50px;
  margin-bottom: 10px;
}
</style>